<?php

class MyModules extends Modules {
    const table_member = 'mc_members';
    const table_member_permission = 'mc_member_permission';
    const table_product_category = 'mc_product_category';
    const table_specs = 'mc_specs';
    const table_product = 'mc_product';
    const table_product_specs = 'mc_product_specs';
    const table_news = 'mc_news';
    const table_news_category = 'mc_news_category';
    const table_product_maker = 'mc_product_maker';
    const table_product_maker_category = 'mc_product_maker_category';
    const table_product_order = 'mc_product_order';
    const table_product_order_detail = 'mc_product_order_detail';
    const table_slider = 'mc_slider';
    const table_customer_link = 'mc_mct_customer_link';
    const table_comments = 'mc_comments';
    const table_support_online = 'mc_support_online';
    const table_customer_contact = 'mc_customer_contact';
    const table_user_online = 'user_online';
    const table_visited = 'mc_visited';
    const table_company_common = 'mc_company_common';

    //not change
    function __construct($aryConfigDB) {
        $this->setConfig($aryConfigDB);
    }

    public function getProductById($productId, &$aryData) {
        try {
            $sql = "SELECT  p.product_id,
                        p.product_title,
                        p.product_content,
                        p.product_title_filter,
                        p.product_search_title,
                        p.product_search_keyword,
                        p.product_search_description,
                        p.product_category_id,
                        p.product_main_image,
                        p.product_small_image,
                        p.product_large_image,
                        p.product_highlight,
                        p.product_price_vnd,
                        p.product_is_vat,
                        p.product_store_name,
                        p.product_warranty_name,
                        p.product_promotional,
                        p.product_promotional_from,
                        p.product_promotional_to,
                        p.product_full_box,
                        p.product_transportation_name,
                        p.product_maker_id,
                        p.product_updated_date,
                        p.product_price_vnd_km,
                        p.product_price_active_km,
                        p.product_highlight,
                        m.product_maker_name_filter,
                        m.product_maker_name,
                        m.product_maker_main_logo
                FROM " . self::table_product . " AS p
                LEFT JOIN " . self::table_product_maker . " AS m
                    ON  p.product_maker_id =  m.product_maker_id
                    WHERE product_del_flag = ?
                    AND product_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productId;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getQuickViewProduct($productId, &$aryData) {
        try {
            $sql = "SELECT  product_id,
                        product_title,
                        product_content,
                        product_title_filter,
                        product_category_id,
                        product_main_image,
                        product_small_image,
                        product_large_image,
                        product_highlight,
                        product_price_vnd,
                        product_store_name,
                        product_promotional,
                        product_transportation_name,
                        product_maker_id,
                        product_price_vnd_km,
                        product_price_active_km,
                        product_highlight
                FROM " . self::table_product . "
                    WHERE product_del_flag = ?
                    AND product_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productId;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductSamePrice() {
        
    }

    public function getProductPriceById($productId, &$aryData) {
        try {
            $sql = "SELECT product_price_vnd,
                        product_price_vnd_km,
                        product_price_active_km,
                        product_title,
                        product_price_vnd_in,
                        product_main_image
                FROM " . self::table_product . "
                WHERE product_id = ?
                AND product_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $productId;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductSameMaker($makerId, $limit, &$aryProductSameMaker) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_main_image,
                        product_highlight,
                        product_price_vnd,
                        product_promotional
                    FROM " . self::table_product . "
                    WHERE product_del_flag = ?
                    AND product_maker_id = ?
                    ORDER BY product_updated_date DESC LIMIT $limit";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $makerId;
            $intOk = $this->getArray($sql, $aryProductSameMaker, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductCategory(&$aryProductCategory) {
        try {
            $sql = "SELECT  category_id,
                        category_name,
                        category_parent,
                        category_level,
                        category_content,
                        category_title_header,
                        category_keyword,
                        category_description,
                        category_name_filter,
                        category_content,
                        category_total_child,
                        category_main_image,
                        category_small_image,
                        category_large_image,
                        category_is_show
                    FROM " . self::table_product_category . "
                    WHERE category_del_flag = ?
                    ORDER BY category_order ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getRootProductCategory(&$aryRootCategory) {
        try {
            $sql = "SELECT  category_id,
                        category_name,
                        category_name_filter
                    FROM " . self::table_product_category . "
                    WHERE category_del_flag = ?
                    AND category_parent = ?
                    ORDER BY category_order ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryRootCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryChildPath($categoryId, $isShow = false) {
        try {
            $sql = "SELECT category_id
                    FROM " . self::table_product_category . "
                WHERE category_del_flag = ? AND category_parent = ?";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            if ($isShow == true) {
                $sql.=" AND category_is_show = ?";
                $aryBin[] = 1;
            }

            $sql.=" ORDER BY category_id DESC";

            $aryResultData = array();

            $intOk = $this->getArray($sql, $aryResultData, $aryBin);

            $aryCategoryId = array();

            foreach ($aryResultData as $key => $value) {

                $aryCategoryId[] = $value['category_id'];

                $aryCategoryId = array_merge($this->getCategoryChildPath($value['category_id'], $isShow), $aryCategoryId);
            }

            return $aryCategoryId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsCategoryChildPath($newsCategoryId) {
        try {
            $sql = "SELECT news_category_id
                    FROM " . self::table_news_category . "
                WHERE news_category_del_flag = ? AND news_category_parent = ?
                ORDER BY news_category_id DESC";

            $aryResultData = array();

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $newsCategoryId;

            $intOk = $this->getArray($sql, $aryResultData, $aryBin);

            $aryCategoryId = array();

            foreach ($aryResultData as $key => $value) {

                $aryCategoryId[] = $value['news_category_id'];

                $aryCategoryId = array_merge($this->getNewsCategoryChildPath($value['news_category_id']), $aryCategoryId);
            }
            return $aryCategoryId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductByListCatId($listCategoryId, $limit, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_main_image,
                        product_small_image,
                        product_large_image
                FROM " . self::table_product . "

                    WHERE product_del_flag = ? ";

            $sql.="AND product_category_id IN($listCategoryId)";


            $sql.=" ORDER BY product_updated_date DESC";

            $sql.=" LIMIT $limit";

            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductInNewsByCatId($listCategoryId, $limit, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_main_image
                FROM " . self::table_product . "

                WHERE product_del_flag = ? ";

            $sql.=" AND product_category_id IN($listCategoryId)";

            $sql.=" ORDER BY product_updated_date DESC";

            $sql.=" LIMIT $limit";

            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProduct, $aryBin);

            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductByType($productType, &$aryProduct, $listCategory = null) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_maker_name,
                        product_store_name,
                        product_main_image,
                        product_small_image,
                        product_large_image,
                        product_highlight,
                        product_promotional,
                        product_price_vnd,
                        product_warranty_name,
                        product_transportation_name,
                        product_is_vat
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";
            $sql.="AND product_type_id = ?";

            if (isset($listCategory)) {
                $sql.=" AND product_category_id IN($listCategory)";
            }
            $sql.=" ORDER BY product_updated_date DESC";
            $sql.=" LIMIT 6";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productType;
            $intOk = $this->getArray($sql, $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProducyByListId($listProductid, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        #product_category_id,
                        #product_category_name,
                        #product_maker_name,
                        #product_store_name,
                        product_main_image,
                        product_small_image,
                        product_large_image,
                        #product_highlight,
                        #product_promotional,
                        product_price_vnd
                        #product_warranty_name,
                        #product_transportation_name,
                        #product_is_vat
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";
            $sql.=" AND product_id IN($listProductid)";

            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSubCatByCatId($categoryId, &$aryCategory) {
        try {
            $sql = "SELECT category_id,
                        category_name,
                        category_main_image,
                        category_name_filter,
                        category_total_child
                FROM " . self::table_product_category . "
                WHERE category_del_flag = ?
                AND category_parent = ?
                ORDER BY category_order ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryParentPath($categoryId) {
        try {
            $sql = "SELECT category_parent FROM " . self::table_product_category . "
                WHERE category_del_flag = ? AND category_id = ?";
            $aryResultData = array();
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            $aryCategoryId = array();
            if ($aryResultData[0]['category_parent'] != 0) {
                $aryCategoryId[] = $aryResultData[0]['category_parent'];
                $aryCategoryId = array_merge($this->getCategoryParentPath($aryResultData[0]['category_parent']), $aryCategoryId);
            }
            return $aryCategoryId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsCategoryParentPath($newsCategoryId) {
        try {
            $sql = "SELECT news_category_parent FROM " . self::table_news_category . "
                WHERE news_category_del_flag = ? AND news_category_id = ?";
            $aryResultData = array();
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $newsCategoryId;
            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            $aryCategoryId = array();
            if ($aryResultData[0]['news_category_parent'] != 0) {
                $aryCategoryId[] = $aryResultData[0]['news_category_parent'];
                $aryCategoryId = array_merge($this->getNewsCategoryParentPath($aryResultData[0]['news_category_parent']), $aryCategoryId);
            }
            return $aryCategoryId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProduct($aryConditions, &$aryProduct, &$aryProductConditions) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_store_name,
                        product_main_image,
                        product_large_image,
                        product_highlight,
                        product_promotional,
                        product_price_vnd,
                        product_warranty_name,
                        product_transportation_name,
                        product_is_vat,
                        product_price_active_km,
                        product_price_vnd_km
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";


            $sql2 = "SELECT product_id,
                        product_maker_id,
                        product_price_vnd
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";

            $aryBin = array();
            $aryBin[] = 0;

            $listCategoryId = $aryConditions['list_category'];

            $sql3 = " AND product_category_id IN($listCategoryId)";

            if ($aryConditions['product_maker_name'] != '' && $aryConditions['product_maker_name'] != 'all') {

                $sql3.=" AND product_maker_name = ?";

                $aryBin[] = $aryConditions['product_maker_name'];
            }

            if (isset($aryConditions['product_price_from']) && is_numeric($aryConditions['product_price_from']) && isset($aryConditions['product_from_to']) && is_numeric($aryConditions['product_from_to'])) {
                $priceFrom = $aryConditions['product_price_from'];
                $priceTo = $aryConditions['product_from_to'];
                $sql3.=" AND product_price_vnd BETWEEN ? AND ?";
                $aryBin[] = $priceFrom;
                $aryBin[] = $priceTo;
            }

            if (isset($aryConditions['list_product_id'])) {

                $listProductId = $aryConditions['list_product_id'];

                $sql3.=" AND product_id IN($listProductId)";
            }

            if (isset($aryConditions['field']) && isset($aryConditions['order'])) {

                $field = $aryConditions['field'];

                $orderType = $aryConditions['order'];

                $sql3.=" ORDER BY $field $orderType";
            } else {

                $sql3.=" ORDER BY product_updated_date DESC";
            }

            $sql.=$sql3;

            $sql2.=$sql3;

            $aryProductConditions = array();

            if ($aryConditions['has_child_category'] == 0) {

                $intOk = $this->getArray($sql2, $aryProductConditions, $aryBin);
            }

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryProduct, $aryBin);

            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductMakerByListId($listMakerId, &$aryProductMaker) {
        try {
            $sql = "SELECT product_maker_id,
                        product_maker_name,
                        product_maker_name_filter,
                        product_maker_main_logo
                FROM " . self::table_product_maker . "
                WHERE product_maker_del_flag = ?
                AND product_maker_id IN($listMakerId)";

            $aryBin = array();
            $aryBin[] = 0;

            $intOk = $this->getArray($sql, $aryProductMaker, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSpecsByCategory($categoryId, &$aryProductSpecs) {
        try {
            $sql = "SELECT specs_id,
                        specs_parent,
                        specs_level,
                        specs_input_type,
                        specs_name,
                        specs_total_child
                FROM " . self::table_specs . "
                WHERE specs_category_id = ?
                AND specs_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $categoryId;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductSpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductSpecsForFilterSpecs($categoryId, &$aryFilterSpecs) {
        try {
            $sql = "SELECT specs_id,
                        specs_name,
                        specs_parent,
                        specs_level,
                        specs_is_show
                FROM " . self::table_specs . "
                WHERE specs_del_flag = ?
                #AND specs_parent != ?
                AND specs_input_type != ?
                AND specs_input_type != ?
                AND specs_category_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 0;
            $aryBin[] = 3;
            $aryBin[] = 5;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryFilterSpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductSpecsByProductId($listProductId, &$aryProductSpecs) {
        try {
            $sql = "SELECT product_specs_specs_id
                FROM " . self::table_product_specs . "
                WHERE product_specs_del_flag = ?
                AND product_specs_product_id IN($listProductId)";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductSpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSpecsDetailByProductId($productId, &$aryProductSpecs) {
        try {
            $sql = "SELECT product_specs_specs_id,
                        product_specs_specs_name
                FROM " . self::table_product_specs . "
                WHERE product_specs_del_flag = ?
                AND product_specs_product_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productId;
            $intOk = $this->getArray($sql, $aryProductSpecs, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductListIdBySpecsId($specsId, $countSpecs, &$aryProductListId) {
        try {
            $sql = "SELECT product_specs_product_id,
                        COUNT(product_specs_specs_id) AS ts_count
                    FROM " . self::table_product_specs . "
                    WHERE product_specs_del_flag = ? AND product_specs_specs_id IN($specsId)
                    GROUP BY product_specs_product_id HAVING ts_count = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $specsId;
            $intOk = $this->getArray($sql, $aryProductListId, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSecsParentPath($specsId) {
        try {
            $sql = "SELECT specs_parent FROM " . self::table_specs . "
                WHERE specs_del_flag = ? AND specs_id = ?";
            $aryResultData = array();
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $specsId;
            $intOk = $this->getArray($sql, $aryResultData, $aryBin);
            $arySpecsId = array();
            if ($aryResultData[0]['specs_parent'] != 0) {
                $arySpecsId[] = $aryResultData[0]['specs_parent'];
                $arySpecsId = array_merge($this->getSecsParentPath($aryResultData[0]['specs_parent']), $arySpecsId);
            }
            return $arySpecsId;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryByListId($listCatParent, &$aryCategoryParent) {
        try {
            $sql = "SELECT category_id,
                        category_name,
                        category_name_filter,
                        category_keyword,
                        category_main_image,
                        category_level,
                        category_title_header,
                        category_description,
                        category_content,
                        category_content_h1
                FROM " . self::table_product_category . "
                WHERE category_del_flag = ?
                AND category_id IN($listCatParent)
                ORDER BY category_level ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryCategoryParent, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function checkExistOrder($productId, $cookieShopCat, &$aryData) {
        try {
            $sql = "SELECT product_order_product_id
                FROM " . self::table_product_order . "
                WHERE product_order_product_id = ?
                AND product_order_cookie_id = ?
                AND product_order_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $productId;
            $aryBin[] = $cookieShopCat;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function checkExistOrderDetail($cookieShopCat, &$aryData) {
        try {
            $sql = "SELECT order_detail_id FROM " . self::table_product_order_detail . "
                        WHERE order_detail_cookie_id = ?
                        AND order_detail_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $cookieShopCat;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertProductOrder($aryOrder) {
        try {
            $intOk = $this->insert(self::table_product_order, $aryOrder);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductOrderByCookie($cookieShopCat, &$aryProductOrder) {
        try {
            $sql = "SELECT product_order_id,
                        product_order_product_id,
                        product_order_product_name,
                        product_order_total_product,
                        product_order_product_price,
                        product_order_total_price,
                        product_order_active,
                        product_order_product_image,
                        product_order_category_id,
                        product_order_category_name,
                        product_order_category_filter
                FROM " . self::table_product_order . "
                WHERE product_order_cookie_id = ?
                AND product_order_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $cookieShopCat;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductOrder, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductIdInOrder($cookieShopCat, &$aryProductOrder) {
        try {
            $sql = "SELECT product_order_product_id
                FROM " . self::table_product_order . "
                WHERE product_order_cookie_id = ?
                AND product_order_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $cookieShopCat;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryProductOrder, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductOrderDetail($cookieShopCat, &$aryProductOrderDetail) {
        try {
            $sql = "SELECT order_detail_full_name,
                        order_detail_address,
                        order_detail_phone_number,
                        order_detail_email,
                        order_detail_address_delivery,
                        order_detail_method_delivery,
                        order_detail_delivery_name,
                        order_detail_method_payment,
                        order_detail_payment_name,
                        order_detail_active,
                        order_detail_company_name,
                        order_detail_company_address,
                        order_detail_company_tax_code
                FROM " . self::table_product_order_detail . "
                WHERE order_detail_del_flag = ?
                AND order_detail_cookie_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $cookieShopCat;
            $intOk = $this->getArray($sql, $aryProductOrderDetail, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateTotalItem($aryOrderUpdate, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product_order, $aryOrderUpdate, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertOrderDetail($aryOrderDetail, &$returnOrderId) {
        try {
            $intOk = $this->insert(self::table_product_order_detail, $aryOrderDetail);
            $returnOrderId = $this->getLastInsertedID();
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateOrder($returnOrderId, $cookieShopCat) {
        try {
            $sql = "UPDATE " . self::table_product_order . " SET product_order_detail_id = ?
                WHERE product_order_cookie_id = ?";
            $aryBin = array();
            $aryBin[] = $returnOrderId;
            $aryBin[] = $cookieShopCat;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateProductOrderDetail($aryOrderDetail, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product_order_detail, $aryOrderDetail, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function activeOderDetail($cookieShopCat) {
        try {
            $sql = "UPDATE " . self::table_product_order_detail . " SET order_detail_active = ?
                WHERE order_detail_cookie_id = ?";
            $aryBin = array();
            $aryBin[] = 1;
            $aryBin[] = $cookieShopCat;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSliderData(&$aryData) {
        try {
            $sql = "SELECT slider_id,
                        slider_title,
                        slider_link,
                        slider_image
                FROM " . self::table_slider . "
                WHERE slider_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getTopNews(&$aryTopNews, $limit, $type = null) {
        try {
            $sql = "SELECT news_id,
                        news_title,
                        news_title_filter,
                        news_content_filter,
                        news_main_image,
                        news_large_image
                FROM " . self::table_news . "
                    WHERE news_del_flag = ?";
            $aryBin = array();
            $aryBin[] = 0;

            if (isset($type)) {
                $sql.=" AND news_type = ?";
                $aryBin[] = $type;
            }
            $sql.=" ORDER BY news_updated_date DESC
                LIMIT $limit";
            $intOk = $this->getArray($sql, $aryTopNews, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsCategory(&$aryCategory, $parentId = null) {
        try {
            $sql = "SELECT  news_category_id,
                        news_category_name,
                        news_category_parent,
                        news_category_level,
                        news_category_filter,
                        news_category_title,
                        news_category_keywords,
                        news_category_description,
                        news_category_product_category,
                        news_category_product_child_cat
                    FROM " . self::table_news_category . "
                    WHERE news_category_del_flag = ? AND news_category_is_show = ?";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = 1;

            if (isset($parentId) & is_numeric($parentId)) {
                $sql.=" AND news_category_parent = ?";
                $aryBin[] = $parentId;
            }
            $sql.=" ORDER BY news_category_order ASC";
            $intOk = $this->getArray($sql, $aryCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsCategoryByListId($listCategoryId, &$aryNewsCategory) {
        try {
            $sql = "SELECT  news_category_id,
                        news_category_name,
                        news_category_filter
                    FROM " . self::table_news_category . "
                    WHERE news_category_del_flag = ?
                    AND news_category_id IN($listCategoryId)
                    ORDER BY news_category_level ASC";
            $aryBin = array();
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryNewsCategory, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsByCategoryId($catId, $limit, &$aryNewsData) {
        try {
            $sql = "SELECT news_id,
                        news_title,
                        news_title_filter,
                        news_content_filter,
                        news_main_image,
                        news_large_image
                FROM " . self::table_news . "
                    WHERE news_del_flag = ?
                    AND news_new_category_id = ?
                ORDER BY news_updated_date DESC
                LIMIT $limit";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $catId;
            $intOk = $this->getArray($sql, $aryNewsData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewByListNewsCategory($strCatId, $limit, &$aryNewsData) {
        try {
            $sql = "SELECT news_id,
                        news_title_filter,
                        news_title,
                        news_main_image,
                        news_large_image,
                        news_content_filter,
                        news_updated_date
                FROM " . self::table_news . "
                WHERE news_del_flag = ?
                AND (news_new_category_id = ? OR news_new_sub_category_id = ?)";

            $sql.=" ORDER BY news_updated_date DESC
                LIMIT $limit";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $strCatId;
            $aryBin[] = $strCatId;
            $intOk = $this->getArray($sql, $aryNewsData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsData($aryConditions, &$aryNewsData) {
        try {
            $sql = "SELECT news_id,
                        news_title_filter,
                        news_title,
                        news_main_image,
                        news_large_image,
                        news_content_filter,
                        news_updated_date
                FROM " . self::table_news . "
                WHERE news_del_flag = ?";

            $aryBin = array();
            $aryBin[] = 0;

            if (isset($aryConditions['news_new_category_id']) && is_numeric($aryConditions['news_new_category_id'])) {
                $sql.=" AND news_new_category_id = ? ";
                $aryBin[] = $aryConditions['news_new_category_id'];
            }

            $sql.=" ORDER BY news_updated_date DESC";

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryNewsData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getSameNewByNewsCategory($strCatId, $limit, &$aryNewsData, $newId) {
        try {
            $sql = "SELECT news_id,
                        news_title_filter,
                        news_title,
                        news_updated_date
                FROM " . self::table_news . "
                WHERE news_del_flag = ?
                AND (news_new_category_id = ? OR news_new_sub_category_id = ?)";

            $sql.=" AND news_id != ?";

            $sql.=" ORDER BY news_updated_date DESC
                LIMIT $limit";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $strCatId;
            $aryBin[] = $strCatId;
            $aryBin[] = $newId;

            $intOk = $this->getArray($sql, $aryNewsData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getTopProduct($type, $limit, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_main_image,
                        product_small_image,
                        product_large_image
                FROM " . self::table_product . "
                WHERE product_del_flag = ?
                AND product_type_id = ?
                ORDER BY product_updated_date DESC
                LIMIT $limit";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $type;
            $intOk = $this->getArray($sql, $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductCategoryInNews($newsCategoryId, &$aryData) {
        try {
            $sql = "SELECT news_category_product_child_cat FROM " . self::table_news_category . "
                WHERE news_category_del_flag = ? AND news_category_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $newsCategoryId;
            $intOk = $this->getArray($sql, $aryData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsDetail($newsId, &$aryNewsData) {
        try {
            $sql = "SELECT  news_id,
                        news_title,
                        news_title_filter,
                        news_main_image,
                        news_new_category_id,
                        news_content,
                        news_content_filter,
                        news_updated_date
                FROM " . self::table_news . "
                WHERE news_del_flag = ?
                AND news_id = ?
                LIMIT 1";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $newsId;
            $intOk = $this->getArray($sql, $aryNewsData, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function updateNewsViews($newsId) {
        try {
            $sql = "UPDATE " . self::table_news . "
                SET news_total_views = news_total_views + 1
                WHERE news_id = ?";
            $aryBin = array();
            $aryBin[] = $newsId;
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getNewsTopViews($limit, &$aryNewsTopViews) {
        try {
            $sql = "SELECT news_id,
                        news_title_filter,
                        news_title,
                        news_updated_date
                FROM " . self::table_news . "
                WHERE news_del_flag = ?";
            $sql.=" ORDER BY news_total_views DESC
                LIMIT $limit";
            $aryBin = array();
            $aryBin[] = 0;

            $intOk = $this->getArray($sql, $aryNewsTopViews, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProCatByNewCat($newsSubCategoryId, &$aryProCat) {
        try {
            $sql = "SELECT news_category_product_child_cat
                    FROM " . self::table_news_category . "
                WHERE news_category_del_flag = ?
                AND news_category_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $newsSubCategoryId;
            $intOk = $this->getArray($sql, $aryProCat, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchProductData($aryConditions, &$aryProduct) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_store_name,
                        product_main_image,
                        product_highlight,
                        product_promotional,
                        product_price_vnd,
                        product_warranty_name,
                        product_transportation_name,
                        product_is_vat,
                        product_price_active_km,
                        product_price_vnd_km
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";

            $aryBin = array();
            $aryBin[] = 0;

            if (isset($aryConditions['product_category_id']) && is_numeric($aryConditions['product_category_id'])) {

                $sql.=" AND product_category_id = ? ";
                $aryBin[] = $aryConditions['product_category_id'];
            }

            if (isset($aryConditions['product_maker_id']) && $aryConditions['product_maker_id'] != 0) {

                $sql.=" AND product_maker_id = ? ";
                $aryBin[] = $aryConditions['product_maker_id'];
            }

            if (strlen($aryConditions['product_keyword']) > 0) {

                $sql.=" AND product_title_search LIKE ?";
                $aryBin[] = "%" . $aryConditions['product_keyword'] . "%";
            }

            if ($aryConditions['product_price_to'] > 0) {
                $priceFrom = $aryConditions['product_price_from'];
                $priceTo = $aryConditions['product_price_to'];
                $sql.=" AND product_price_vnd BETWEEN ? AND ?";
                $aryBin[] = $priceFrom;
                $aryBin[] = $priceTo;
            }

            $sql.=" ORDER BY product_price_vnd DESC";

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchCategoryInProduct($aryConditions, &$aryCategoryProduct) {
        try {
            $sql = "SELECT product_category_id,
                        product_category_name
                FROM " . self::table_product . "
                WHERE product_del_flag = ?";
            $sql.=" AND product_title_search LIKE ? ";

            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = "%" . $aryConditions['keyword'] . "%";

            $intOk = $this->getArray($sql, $aryCategoryProduct, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchAllProduct($aryConditions, &$aryProductSearch) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_main_image,
                        product_highlight,
                        product_price_vnd
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";

            $aryBin = array();
            $aryBin[] = 0;

            $sql.=" AND product_title_search LIKE ? ";

            $aryBin[] = "%" . $aryConditions['keyword'] . "%";

            if (isset($aryConditions['product_category_id']) && is_numeric($aryConditions['product_category_id'])) {

                $sql.=" AND product_category_id = ? ";
                $aryBin[] = $aryConditions['product_category_id'];
            }

            $sql.=" ORDER BY product_price_vnd DESC";

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryProductSearch, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function searchAllNews($aryConditions, &$arySearchNews) {
        try {
            $sql = "SELECT news_id,
                        news_title_filter,
                        news_title,
                        news_content_filter,
                        news_main_image
                FROM " . self::table_news . "
                WHERE news_del_flag = ?
                AND news_title_search LIKE ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = "%" . $aryConditions['keyword'] . "%";

            $intOk = $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $arySearchNews, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function countTotalNews($aryConditions, &$arySearchNews) {
        try {
            $sql = "SELECT news_id
                FROM " . self::table_news . "
                WHERE news_del_flag = 0
                AND news_title_search LIKE ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = "%" . $aryConditions['keyword'] . "%";
            $intOk = $this->getArray($sql, $arySearchNews, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductInfoByType($aryConditions, &$aryProuctInfo) {
        try {
            $sql = "SELECT product_id,
                        product_title,
                        product_title_filter,
                        product_category_id,
                        product_category_name,
                        product_store_name,
                        product_main_image,
                        product_highlight,
                        product_promotional,
                        product_price_vnd,
                        product_warranty_name,
                        product_transportation_name,
                        product_is_vat,
                        product_price_active_km,
                        product_price_vnd_km
                FROM " . self::table_product . "
                    WHERE product_del_flag = ? ";
            $aryBin = array();
            $aryBin[] = 0;

            if (isset($aryConditions['product_category_id']) && $aryConditions['product_category_id'] != 'all') {

                $listCategory = $aryConditions['product_category_id'];

                $sql.=" AND product_category_id IN($listCategory)";
            }

            if (isset($aryConditions['product_type_id']) && is_numeric($aryConditions['product_type_id'])) {

                $productType = $aryConditions['product_type_id'];

                $sql.=" AND product_type_id = ?";

                $aryBin[] = $productType;
            }

            $sql.=" ORDER BY product_price_vnd DESC";

            $this->paging($sql, $aryConditions['current_page'], $aryConditions['record_per_page'], $aryProuctInfo, $aryBin);

            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteAllShopCat($aryConditions) {
        try {
            $sql = "UPDATE " . self::table_product_order . "
                SET product_order_del_flag = ?
                WHERE product_order_cookie_id = ?";
            $aryBin = array();
            $aryBin[] = 1;
            $aryBin[] = $aryConditions['product_order_cookie_id'];
            $intOk = $this->Excute($sql, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function deleteOrderById($aryDelete, $aryConfig) {
        try {
            $intOk = $this->update(self::table_product_order, $aryDelete, $aryConfig);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function saveCustomerLink($aryCustomerLink) {
        try {
            $intOk = $this->insert(self::table_customer_link, $aryCustomerLink);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function insertCommentsProduct($aryComments) {
        try {
            $intOk = $this->insert(self::table_comments, $aryComments);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductComments($productId, &$aryComments) {
        try {
            $sql = "SELECT comments_id,
                        comments_detail_id,
                        comments_title,
                        comments_name,
                        comments_email,
                        comments_comments,
                        comments_datetime
                FROM " . self::table_comments . "

                WHERE comments_del_flat = ? ";

            $sql.=" AND comments_detail_id IN($productId)";

            $sql.=" ORDER BY comments_id DESC";

            $aryBin = array();
            $aryBin[] = 0;
            //$sql.=" LIMIT $limit";

            $intOk = $this->getArray($sql, $aryComments, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function saveCustomerContact($aryCustomer) {
        try {
            $intOk = $this->insert(self::table_customer_contact, $aryCustomer);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getProductImageData(&$aryProductImage, $productId) {
        try {
            $sql = "SELECT product_image_product_id,
                    product_image_main_image,
                    product_image_small_image,
                    product_image_large_image
                FROM " . self::table_product_image . "
                WHERE product_image_del_flag = ?
                AND product_image_product_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $productId;
            $intOk = $this->getArray($sql, $aryProductImage, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getCategoryContent($categoryId, &$aryContent) {
        try {
            $sql = "SELECT category_content_content FROM " . self::table_category_content . "
                    WHERE category_content_del_flag = ? AND category_content_category_id = ?";
            $aryBin = array();
            $aryBin[] = 0;
            $aryBin[] = $categoryId;
            $intOk = $this->getArray($sql, $aryContent, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function userOnline2() {
        try {
            $session = session_id();

            $time = time();

            $time_check = $time - 300; //SET TIME 5 Minute

            $sql = "SELECT session, time FROM " . self::table_user_online . " WHERE session = ?";

            $aryBin = array();

            $aryBin[] = $session;

            $intOk = $this->getArray($sql, $aryData, $aryBin);

            if (count($aryData) == 0) {

                $aryInsert = array();
                $aryInsert['session'] = $session;
                $aryInsert['time'] = $time;

                $this->insert(self::table_user_online, $aryInsert);

                $visitedSql = "UPDATE " . self::table_visited . " set mc_visited = mc_visited + 1";

                $this->Excute($visitedSql);
            } else {

                $sql2 = "UPDATE " . self::table_user_online . " SET time='$time' WHERE session = '$session'";

                $this->Excute($sql2);
            }

            $sql3 = "SELECT session, time FROM " . self::table_user_online;

            $this->getArray($sql3, $aryResultData);

            $count_user_online = count($aryResultData);

            // if over 5 minute, delete session
            $sql4 = "DELETE FROM " . self::table_user_online . " WHERE time < ?";

            $aryBin = array();

            $aryBin[] = $time_check;

            $this->Excute($sql4, $aryBin);

            $visitQuery = "SELECT mc_visited FROM " . self::table_visited;

            $aryVisit = array();

            $this->getArray($visitQuery, $aryVisit);

            if (count($aryVisit) == 0) {
                $aryVisit[0]['mc_visited'] = 1;
                $aryVisitInsert = array();
                $aryVisitInsert['mc_visited'] = 1;
                $aryVisitInsert['mc_visited_session'] = $session;
                $this->insert(self::table_visited, $aryVisitInsert);
            }

            $aryData = array();
            $aryData['visited'] = $aryVisit[0]['mc_visited'];
            $aryData['online'] = $count_user_online;

            return $aryData;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getIntroductionData($type, &$aryIntroduction) {
        try {
            $sql = "SELECT mc_company_common_id,
                        mc_company_common_title,
                        mc_company_common_content
                FROM " . self::table_company_common . "
                WHERE mc_company_commom_type = ?
                AND mc_company_common_del_flag = ?
                ORDER BY mc_company_common_update_date DESC LIMIT 1";
            $aryBin = array();
            $aryBin[] = $type;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryIntroduction, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getBaogiaTitle($type, &$aryBaogia) {
        try {
            $sql = "SELECT 
                        mc_company_common_title,
                        mc_company_common_title_filter
                FROM " . self::table_company_common . "
                WHERE mc_company_commom_type = ?
                AND mc_company_common_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $type;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryBaogia, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

    public function getIntroductionByTitle(&$aryIntroduction, $title) {
        try {
            $sql = "SELECT mc_company_common_id,
                        mc_company_common_title,
                        mc_company_common_content
                FROM " . self::table_company_common . "
                WHERE mc_company_common_title_filter = ?
                AND mc_company_common_del_flag = ?";
            $aryBin = array();
            $aryBin[] = $title;
            $aryBin[] = 0;
            $intOk = $this->getArray($sql, $aryIntroduction, $aryBin);
            return $intOk;
        } catch (Exception $exc) {
            $this->writeLog($exc->getMessage(), __FUNCTION__, __FILE__, __LINE__);
        }
    }

}

?>
